package com.x.erp.dao;

import com.x.erp.model.Country;
import com.x.framework.dao.BaseDao;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class CountryDao extends BaseDao {
    private final static String selectCountryListSql = "SELECT * FROM BASE_COUNTRY WHERE 1 = 1 ";
    public List<Country> selectCountryList(Country country) throws Exception {
        StringBuilder sb = new StringBuilder(selectCountryListSql);
        List<Object> params = new ArrayList<Object>();
        if(country.getCountryId() != null){
            sb.append("AND COUNTRY_ID = ? ");
            params.add(country.getCountryId());
        }
        if(country.getCountryName() != null){
            sb.append("AND COUNTRY_NAME = ? ");
            params.add(country.getCountryName());
        }
        return this.queryForList(sb.toString(), Country.class, params);
    }
}
